//
//  PKRootRithtViewController.m
//  Awhile
//
//  Created by lanou on 15/9/25.
//  Copyright (c) 2015年 lanou. All rights reserved.
//

#import "PKRootRithtViewController.h"
#import "PKBaseViewController.h"
@interface PKRootRithtViewController ()
@property(nonatomic, strong)NSArray *classArray;
@property(nonatomic, strong)PKBaseViewController *baseVC;
@property(nonatomic, strong)UINavigationController *navi;
@end

@implementation PKRootRithtViewController

- (NSArray *)classArray
{
    if (!_classArray) {
        _classArray = [NSArray arrayWithObjects:@"SoundBookViewController",@"MusicViewController",@"ChildrenViewController", nil];
    }
    return _classArray;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    _baseVC = [[NSClassFromString(self.classArray[0]) alloc]init];
    // 创建一个导航控制器，让它去管理将要显示的界面，这样将要显示的界面才有push功能。因为导航控制器需要一直存在，所以可以把它定义成为一个属性
    _navi = [[UINavigationController alloc]initWithRootViewController:_baseVC];
    _navi.navigationBar.hidden = YES;
    _baseVC.changeFrameVC = self;
    [self.view addSubview:_navi.view];
    
}
// 抽屉效果
- (void)changeFrame
{
    CGRect newFram = self.view.frame;
    if (self.view.frame.origin.x == 0) {
        newFram.origin.x = [UIScreen mainScreen].bounds.size.width - 40;
    }else
    {
        newFram.origin.x = 0;
    }
    [UIView animateWithDuration:1 animations:^{
        self.view.frame = newFram;
    }];
}

- (void)changeViewIndex:(NSInteger)indexPath
{

    // 用NSClassFromString函数通过字符串获取到某个类，然后动态的创建不同控制器，同时使用多态的思想，让父类指针接收子类对象
    [_navi.view removeFromSuperview];
    _baseVC = [[NSClassFromString(self.classArray[indexPath]) alloc]init];
    _navi = [[UINavigationController alloc]initWithRootViewController:_baseVC];
    _baseVC.changeFrameVC = self;
    // 隐藏导航控制器的导航栏
    _navi.navigationBar.hidden = YES;
    [self.view addSubview:_navi.view];

    [self changeFrame];
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

@end
